var prompt = document.getElementsByClassName("prompt");

var userIdmessage = document.getElementById("userIdmessage");

if (userIdmessage.innerHTML !== "") {
    var ifnewuser = document.getElementById("ifnewuser");
    axios({
        url: '/judgeOfNewUser',
        method: 'post',
        params: {
            userId: userIdmessage.innerHTML,
        }
    })
        .then(function (data) {
           
            if (data.data.data.object == "1") {  
                ifnewuser.innerHTML = data.data.data.object
            } else {
                ifnewuser.innerHTML = data.data.data.object
            }

        })
        .catch(function (error) {
            console.log(error)
        })
}


var cover = document.getElementById("cover");
var modal = document.getElementById("modal");
var logincover = document.getElementById("logincover");
var loginmodal = document.getElementById("loginmodal");

var wordone = document.getElementById("wordone");
var wordtwo = document.getElementById("wordtwo");

var selfaccountloginaccount = document.getElementById("selfaccountloginaccount");
var selfaccountloginpassword = document.getElementById("selfaccountloginpassword")
var selfaccountloginbtn = document.getElementById("selfaccountloginbtn")
selfaccountloginbtn.onclick = function () {
    hidesearchinput.style.display = "none";
    axios({
        url: '/toLogin',
        method: 'post',
        params: {
            account: selfaccountloginaccount.value,
            password: selfaccountloginpassword.value
        }
    })
        .then(function (data) {
          
            if (data.data.data.message=="登录成功"){
                $('.prompt').show().delay(1000).fadeOut();
                prompt[0].innerText = "登录成功";
                window.location.reload();
            }else{
                $('.prompt').show().delay(1000).fadeOut();
                prompt[0].innerText = data.data.data.message;
            }
        })
        .catch(function (error) {
            console.log(error)
        })
}


var toontherzh = document.getElementById("toontherzh");

if (userIdmessage.innerHTML == "") {
    toontherzh.style.display = "none"
} else {
    toontherzh.style.display = "none"
}


var vipviewheadimg  = document.getElementById("vipviewheadimg");

if (userIdmessage.innerHTML !== "") {
    /*登录成功之后进行遍历个人信息 */
    axios({
        url: '/findUserById',
        method: 'get',
        params: {
            userId: userIdmessage.innerHTML,
        }
    })
        .then(function (data) {
            /*头像的遍历 */
            var topheadimg  = document.getElementById("topheadimg")
            var vipviewheadimg  = document.getElementById("vipviewheadimg")
                topheadimg.src = data.data.data.object.src
                vipviewheadimg.src = data.data.data.object.src   

            var viptype   = document.getElementById("viptype");
            viptype.innerHTML = data.data.data.object.vip;
            /*判断是否是会员 */
            
            var hidebutton = document.getElementById("hidebutton");
            if (viptype.innerHTML == "0") {
                hidebutton.innerHTML="开通VIP"
                wordtwo.style.display = "none"
                wordone.style.display = "block"
            } else {
                hidebutton.innerHTML = "续费VIP"
                wordone.style.display = "none"
                wordtwo.style.display = "block"
            }

                var vipnickname  = document.getElementById("vipnickname");
                var iflogin = document.getElementById("iflogin")
                if (data.data.data.object.nickname.length>5){
                    var lastnickname = data.data.data.object.nickname.replace(/^\s*|\s*$/g, "").substring(0, 5) + "...";
                    console.log(lastnickname)
                    vipnickname.innerHTML = lastnickname
                    iflogin.innerHTML = lastnickname

                }else{
                    vipnickname.innerHTML = data.data.data.object.nickname
                    iflogin.innerHTML = data.data.data.object.nickname
                }



        })
        .catch(function (error) {
            console.log('失败')
        })
}

var toontherzh = document.getElementById("toontherzh");
var vipnickname = document.getElementById("vipnickname");
/*点击开通会员！！进入重置会员页面！！！！ */
/*注意如果已经开通的话，这里显示续费！！！！ */
/*兑换会员  赠送好友 */
/*开通会员德弹窗 */

var cover = document.querySelector("#cover");
var modal = document.querySelector("#modal");
var closes = document.getElementById("closes");

var wlcover = document.getElementById("wlcover");
var wl = document.getElementById("wl");

if(userIdmessage.innerHTML!==""){
    closes.addEventListener("click",function(){
        /*首先判断是否是老用户！！！ */
        if (ifnewuser.innerHTML == "1") {
            /*出现一个挽留的弹窗！！！！ */
            wlcover.style.display = "block";   //显示遮罩层
            wl.style.display = "block";   //显示弹出层
            var yesclose = document.getElementById("yesclose");
            var noclose = document.getElementById("noclose");
            yesclose.onclick = function () {
                hidesearchinput.style.display = "none";
                cover.style.display = "none";
                modal.style.display = "none";
                wlcover.style.display = "none";   //显示遮罩层
                wl.style.display = "none";   //显示弹出层
            }
            noclose.onclick = function () {
                hidesearchinput.style.display = "none";
                wlcover.style.display = "none";   //显示遮罩层
                wl.style.display = "none";   //显示弹出层
            }
        } else {
            hidesearchinput.style.display = "none";
            cover.style.display = "none";
            modal.style.display = "none";
            wlcover.style.display = "none";   //显示遮罩层
            wl.style.display = "none";   //显示弹出层
        }


    
    })
}else{
    closes.addEventListener("click", function () {
        /*出现一个挽留的弹窗！！！！ */
        wlcover.style.display = "block";   //显示遮罩层
        wl.style.display = "block";   //显示弹出层
        var yesclose = document.getElementById("yesclose");
        var noclose = document.getElementById("noclose");
        yesclose.onclick = function () {
            hidesearchinput.style.display = "none";
            cover.style.display = "none";
            modal.style.display = "none";
            wlcover.style.display = "none";   //显示遮罩层
            wl.style.display = "none";   //显示弹出层
        }
        noclose.onclick = function () {
            hidesearchinput.style.display = "none";
            wlcover.style.display = "none";   //显示遮罩层
            wl.style.display = "none";   //显示弹出层
        }
    })
}


/*切换账号的操作！！！！ */

var morezhcover = document.getElementById("morezhcover");
var morezh = document.getElementById("morezh");
toontherzh.onclick = function () {
    hidesearchinput.style.display = "none";
    morezhcover.style.display = "block";
    morezh.style.display = "block";
}

var closemorezh = document.getElementById("closemorezh");
closemorezh.onclick = function () {
    hidesearchinput.style.display = "none";
    morezhcover.style.display = "none";
    morezh.style.display = "none";
}
var nomore = document.getElementById("nomore");
nomore.onclick = function () {
    hidesearchinput.style.display = "none";
    morezhcover.style.display = "none";
    morezh.style.display = "none";
}

var vipidall = document.getElementsByClassName("vipid");
/*点击去支付 */
var payapplybtn = document.getElementById("payapplybtn");
payapplybtn.onclick = function () {
    if (userIdmessage.innerHTML == "") {
        $('.prompt').show().delay(1000).fadeOut();
        prompt[0].innerText = "尚未登录，请先登录";
    } else {
        /*登录之后先进行查询积分，然后如果签到就进行签到 */
      
        for (let i = 0; i < allonevipdivall.length; i++) {
            if (allonevipdivall[i].style.background !== "") {
                // alert(vipidall[i].innerHTML.replace(/^\s*|\s*$/g, ""))
                var vipId = vipidall[i].innerHTML.replace(/^\s*|\s*$/g, "")
                axios({
                    url: '/addPayOrder',
                    method: 'post',
                    params: {
                        vipId: vipId,
                        userId: userIdmessage.innerHTML,
                    }
                })
                    .then(function (data) { 
                        /*添加订单成功之后进行遍历订单获取订单信息 */
                        axios({
                            url: '/findOrderInnerJoinUser',
                            method: 'get',
                            params: {
                                payVipOrderId: data.data.data.object.payVipOrderId,
                            }
                        })
                            .then(function (data) {
                              
                                var payNo = data.data.data.object.payNo  //订单号码
                                var userName = data.data.data.object.userName  //订单人
                                var goodsName = data.data.data.object.goodsName  //订单vip类型名称
                                var nowPrice = data.data.data.object.nowPrice  //订单价格
                                var payVipOrderId = data.data.data.object.payVipOrderId  //订单id

                                /*进行支付 */
                                axios({
                                    url: '/payFor',
                                    method: 'get',
                                    params: {
                                        payVipOrderId: data.data.data.object.payVipOrderId,
                                    }
                                })
                                    .then(function (data) {

                                        window.location.href = 'http://42.194.158.211:8080/video/alipay/payFor?payVipOrderId' + '=' + `${payVipOrderId}`

                                        /*存储 */
                                        localStorage.setItem("payVipOrderId", `${payVipOrderId}`);

                                    })
                                    .catch(function (error) {
                                        console.log('支付订单失败')
                                    })

                            })
                            .catch(function (error) {
                                
                                console.log('遍历支付订单失败')
                            })



                    })
                    .catch(function (error) {
                      
                        console.log('添加订单失败')
                    })



            }
        }
    }
}




var allwaysdivs = document.getElementById("hhh").querySelectorAll("div");
var allwaysbuttons = document.getElementById("hhh").querySelectorAll("button");
// var words = document.getElementById("words");
var money = document.getElementById("money");



var btn = document.getElementById("btn");
var hhh = document.getElementById("hhh");
var leftbtn = document.getElementById("leftbtn");
btn.addEventListener("click", function () {
    if (ifnewuser.innerHTML == "1") {
        /*新用户 */
        if (hhh.style.marginLeft == "") {
            hhh.style.marginLeft = "-645px";
            hhh.style.transition = "all 1s";
            btn.style.display = "block";
            leftbtn.style.display = "block";
        } else {
            console.log("123")
            hhh.style.marginLeft = "-1290px";
            hhh.style.transition = "all 1s";
            btn.style.display = "none";
            leftbtn.style.display = "block";
        }
    } else {
        /*老用户 */
        hhh.style.marginLeft = "-645px";
        hhh.style.transition = "all 1s";
        btn.style.display = "none";
        leftbtn.style.display = "block";
    }

})



leftbtn.onclick = function () {
    if (ifnewuser.innerHTML == "1") {
        /*新用户 */
        if (hhh.style.marginLeft == "-1290px") {
            hhh.style.marginLeft = "-645px";
            hhh.style.transition = "all 1s";
            btn.style.display = "block";
            leftbtn.style.display = "block";
        } else {
            hhh.style.marginLeft = "";
            hhh.style.transition = "all 1s";
            btn.style.display = "block";
            leftbtn.style.display = "none";
        }
    } else {
        hhh.style.marginLeft = "";
        hhh.style.transition = "all 1s";
        btn.style.display = "block";
        leftbtn.style.display = "none";
        /*老用户 */


    }


}


var qb = document.getElementById("qb");
var hideqb = document.getElementById("hideqb");
var show = document.getElementById("show");


qb.onclick = function () {
    hidesearchinput.style.display = "none";

    if (show.src == "http://localhost:3000/publics/front-stage/img/show.png") {
        show.src = "http://localhost:3000/publics/front-stage/img/hide.png"
    } else {
        show.src = "http://localhost:3000/publics/front-stage/img/show.png";
    }
    if (hideqb.style.display == "none") {
        hideqb.style.display = "block";
    } else {
        hideqb.style.display = "none";
    }
}

var toout = document.getElementById("toout");
var tologin = document.getElementById("tologin");

/*点击退出！！！ */
toout.onclick = function () {
    hidesearchinput.style.display = "none";
    axios({
        url: '/logout',
        method: 'post',
    })
        .then(function (data) {
            window.location.href = "/index"
            // userIdmessage.innerHTML = localStorage.removeItem("userid")
        })
        .catch(function (error) {
            console.log('失败')
        })
}


/*导航栏头像隐藏下拉栏的开通会员 */
var hidebutton = document.getElementById("hidebutton");
hidebutton.onclick = function () {
    hidesearchinput.style.display = "none";
    /*点开隐藏框的时候直接隐藏下拉栏 */
    headimgHide.style.display = "none";
    cover.style.display = "block";   //显示遮罩层
    modal.style.display = "block";   //显示弹出层
    var wlcover = document.getElementById("wlcover");
    var wl = document.getElementById("wl");
}


var emailregister = document.getElementById("emailregister")//邮箱注册
var changepassword = document.getElementById("changepassword");//忘记密码
var emailpasswordlogin = document.getElementById("emailpasswordlogin");//邮箱密码登录
var selfaccountregister = document.getElementById("selfaccountregister");//自定义账号注册
var emailcodelogin = document.getElementById("emailcodelogin");//邮箱验证码登录
var selfaccountlogin = document.getElementById("selfaccountlogin");//自定义账号登录

var emailcodeloginthere = document.getElementById("emailcodeloginthere");//邮箱验证码登录
var selfaccountregisterthere = document.getElementById("selfaccountregisterthere");//自定义账户注册
var selfaccountloginthere = document.getElementById("selfaccountloginthere");//自定义账号登录
var loginthrer = document.getElementById("loginthrer");//邮箱密码登录
var registerthere = document.getElementById("registerthere");//邮箱注册
var newpasswordthere = document.getElementById("newpasswordthere");//忘记密码

emailregister.onclick = function () {
    loginmodal.style.height = "400px"
    hidesearchinput.style.display = "none";
    emailregister.style.color = "white";
    emailregister.style.backgroundColor = "#00a1d6";
    emailpasswordlogin.style.backgroundColor = "transparent";
    changepassword.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "transparent";
    emailcodelogin.style.backgroundColor = "transparent";
    selfaccountlogin.style.backgroundColor = "transparent";
    emailpasswordlogin.style.color = "#666";
    changepassword.style.color = "#666";
    selfaccountregister.style.color = "#666";
    emailcodelogin.style.color = "#666";
    selfaccountlogin.style.color = "#666";
    loginthrer.style.display = "none";
    newpasswordthere.style.display = "none";
    registerthere.style.display = "block";
    logincover.style.display = "block";
    emailcodeloginthere.style.display = "none";
    selfaccountregisterthere.style.display = "none";
    selfaccountloginthere.style.display = "none";
}
/*更改密码 */

changepassword.onclick = function () {
    logincover.style.display = "block";
    loginmodal.style.height = "400px"
    hidesearchinput.style.display = "none";
    emailregister.style.color = "#666";
    emailpasswordlogin.style.color = "#666";
    changepassword.style.color = "white";
    changepassword.style.backgroundColor = "#00a1d6";
    emailpasswordlogin.style.backgroundColor = "transparent";
    emailregister.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "transparent";
    emailcodelogin.style.backgroundColor = "transparent";
    selfaccountlogin.style.backgroundColor = "transparent";

    selfaccountregister.style.color = "#666";
    emailcodelogin.style.color = "#666";
    selfaccountlogin.style.color = "#666";
    loginthrer.style.display = "none";
    newpasswordthere.style.display = "block";
    registerthere.style.display = "none";
    emailcodeloginthere.style.display = "none";
    selfaccountregisterthere.style.display = "none";
    selfaccountloginthere.style.display = "none";

}
/*邮箱密码登录 */

emailpasswordlogin.onclick = function () {
    logincover.style.display = "block";
    loginmodal.style.height = "300px"
    hidesearchinput.style.display = "none";
    loginthrer.style.display = "block";
    newpasswordthere.style.display = "none";
    registerthere.style.display = "none";
    emailcodeloginthere.style.display = "none";
    selfaccountregisterthere.style.display = "none";
    selfaccountloginthere.style.display = "none";

    emailregister.style.color = "#666";
    emailpasswordlogin.style.color = "white";
    emailpasswordlogin.style.backgroundColor = "#00a1d6";
    changepassword.style.backgroundColor = "transparent";
    emailregister.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "transparent";
    emailcodelogin.style.backgroundColor = "transparent";
    selfaccountlogin.style.backgroundColor = "transparent";
    changepassword.style.color = "#666";
    selfaccountregister.style.color = "#666";
    emailcodelogin.style.color = "#666";
    selfaccountlogin.style.color = "#666";

}
/*邮箱验证码登录 */

emailcodelogin.onclick = function () {
    logincover.style.display = "block";
    loginmodal.style.height = "300px"
    hidesearchinput.style.display = "none";
    loginthrer.style.display = "none";
    newpasswordthere.style.display = "none";
    registerthere.style.display = "none";
    emailcodeloginthere.style.display = "block";
    selfaccountregisterthere.style.display = "none";
    selfaccountloginthere.style.display = "none";
    emailregister.style.color = "#666";
    emailpasswordlogin.style.color = "#666";
    changepassword.style.color = "#666";
    selfaccountregister.style.color = "#666";
    emailcodelogin.style.color = "white";
    emailcodelogin.style.backgroundColor = "transparent";
    emailpasswordlogin.style.backgroundColor = "transparent";
    emailregister.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "transparent";
    emailcodelogin.style.backgroundColor = "#00a1d6";
    selfaccountlogin.style.backgroundColor = "transparent";
    selfaccountlogin.style.color = "#666";
}

selfaccountregister.onclick = function () {
    logincover.style.display = "block";
    loginmodal.style.height = "300px"
    hidesearchinput.style.display = "none";
    loginthrer.style.display = "none";
    newpasswordthere.style.display = "none";
    registerthere.style.display = "none";
    emailcodeloginthere.style.display = "none";
    selfaccountregisterthere.style.display = "block";
    selfaccountloginthere.style.display = "none";
    emailregister.style.color = "#666";
    emailpasswordlogin.style.color = "#666";
    changepassword.style.color = "#666";
    selfaccountregister.style.color = "white";
    selfaccountregister.style.backgroundColor = "transparent";
    emailpasswordlogin.style.backgroundColor = "transparent";
    emailregister.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "#00a1d6";
    emailcodelogin.style.backgroundColor = "transparent";
    selfaccountlogin.style.backgroundColor = "transparent";
    emailcodelogin.style.color = "#666";
    selfaccountlogin.style.color = "#666";
}

selfaccountlogin.onclick = function () {
    logincover.style.display = "block";
    loginmodal.style.height = "300px"
    hidesearchinput.style.display = "none";
    loginthrer.style.display = "none";
    newpasswordthere.style.display = "none";
    registerthere.style.display = "none";
    emailcodeloginthere.style.display = "none";
    selfaccountregisterthere.style.display = "none";
    selfaccountloginthere.style.display = "block";
    emailregister.style.color = "#666";
    emailpasswordlogin.style.color = "#666";
    changepassword.style.color = "#666";
    selfaccountregister.style.color = "#666";
    emailcodelogin.style.color = "#666";
    selfaccountlogin.style.color = "white";
    selfaccountlogin.style.backgroundColor = "#00a1d6";
    emailpasswordlogin.style.backgroundColor = "transparent";
    emailregister.style.backgroundColor = "transparent";
    selfaccountregister.style.backgroundColor = "transparent";
    emailcodelogin.style.backgroundColor = "transparent";
    changepassword.style.backgroundColor = "transparent";
}









/*获取验证码的定时器操作！！！！ */
var emailregisteremail = document.getElementById("emailregisteremail");
var emailregisterpassword = document.getElementById("emailregisterpassword");
var emailregisterrepassword = document.getElementById("emailregisterrepassword");
var emailregistercode = document.getElementById("emailregistercode");
var getyzm = document.getElementById("getyzm");
/*获取验证码的定时器！*/
var countDownNumber = 60;
var countDownTimer;
function countDownFunction() {
    if (countDownNumber == 0) {
        getyzm.innerHTML = "重新发送";
        emailcodelogingetyzm.innerHTML = "重新发送";
        newpasswordgetyzm.innerHTML = "重新发送";
        $('#getyzm').removeAttr("disabled");
        $('#emailcodelogingetyzm').removeAttr("disabled");
        $('#newpasswordgetyzm').removeAttr("disabled");
        countDownNumber = 60;
        clearInterval(countDownTimer);
    } else {
        countDownNumber--;
        getyzm.innerHTML = countDownNumber + "s秒后重试";
        emailcodelogingetyzm.innerHTML = countDownNumber + "s秒后重试";
        newpasswordgetyzm.innerHTML = countDownNumber + "s秒后重试";
        $('#getyzm').attr("disabled", "true");
        $('#emailcodelogingetyzm').attr("disabled", "true");
        $('#newpasswordgetyzm').attr("disabled", "true");

    }
}


newpasswordgetyzm.onclick = function () {
    axios({
        url: '/sendEmail',
        method: 'post',
        params: {
            to: newpasswordemail.value,
        }
    })
        .then(function (data) {
            countDownTimer = setInterval(function () {
                countDownFunction();
            }, 1000);
            $('.prompt').show().delay(1000).fadeOut();
            prompt[0].innerText = "获取验证码成功！";
            /*通过js设置这个按钮不可点击 */

            newpasswordbtn.onclick = function () {
                axios({
                    url: '/findMissPassword',
                    method: 'put',
                    params: {
                        code: newpasswordcode.value,
                        email: newpasswordemail.value,
                        password: newpasswordepassword.value,
                        rePassword: newpassworderepassword.value,

                    }
                })
                    .then(function (data) {
                        console.log("根据邮箱更改密码成功")
                        window.location.reload()
                    })
                    .catch(function (error) {
                      
                        console.log('根据邮箱更改密码失败')
                    })

            }
        })
        .catch(function (error) {
           
            console.log('失败')
        })
}


getyzm.onclick = function () {
    hidesearchinput.style.display = "none";
    // countDownFunction()
  
    axios({
        url: '/sendEmail',
        method: 'post',
        params: {
            to: emailregisteremail.value,
        }
    })
        .then(function (data) {
            countDownTimer = setInterval(function () {
                countDownFunction();
            }, 1000);
            $('.prompt').show().delay(1000).fadeOut();
            prompt[0].innerText = "获取验证码成功！";
            /*通过js设置这个按钮不可点击 */
            $('#getyzm').attr("disabled", "disabled");
        })
        .catch(function (error) {
           
            console.log('失败')
        })

}


/*获取完邮箱验证码之后进行邮箱注册环节！！！ */
var emailregisterbtn = document.getElementById("emailregisterbtn");
emailregisterbtn.onclick = function () {
    hidesearchinput.style.display = "none";
    axios({
        url: '/emailAddUser',
        method: 'put',
        params: {
            code: emailregistercode.value,
            email: emailregisteremail.value,
            passWord: emailregisterpassword.value,
            rePassWord: emailregisterrepassword.value,
        }
    })
        .then(function (data) {
         
            $('.prompt').show().delay(1000).fadeOut();
            prompt[0].innerText = data.data.data.message;
           
        })
        .catch(function (error) {
          
            console.log('邮箱注册失败')
        })
}


/*邮箱验证码登录 */
var emailcodelogingetyzm = document.getElementById("emailcodelogingetyzm");
/*邮箱验证码登录 */
var emailcodeemail = document.getElementById("emailcodeemail");
var emailcodecode = document.getElementById("emailcodecode");
var emailcodebtn = document.getElementById("emailcodebtn");
emailcodelogingetyzm.onclick = function () {
    hidesearchinput.style.display = "none";
  
    axios({
        url: '/sendEmail',
        method: 'post',
        params: {
            to: emailcodeemail.value,
        }
    })
        .then(function (data) {
           
            countDownTimer = setInterval(function () {
                countDownFunction();
            }, 1000);
            $('.prompt').show().delay(1000).fadeOut();
            prompt[0].innerText = data.data.data.message;
            /*通过js设置这个按钮不可点击 */
            $('#emailcodelogingetyzm').attr("disabled", "disabled");

            emailcodebtn.onclick = function () {
                axios({
                    url: '/emailLogin',
                    method: 'post',
                    params: {
                        code: emailcodecode.value,
                        email: emailcodeemail.value,
                    }
                })
                    .then(function (data) {
                        $('.prompt').show().delay(1000).fadeOut();
                        prompt[0].innerText = data.data.data.message;
                        window.location.reload();
                    })
                    .catch(function (error) {
                       
                        console.log('邮箱验证码登录失败')
                    })
            }


        })
        .catch(function (error) {
            console.log('失败')
        })
}










/*登录更改密码的弹窗的消失 */
var closelogintc = document.querySelectorAll(".closelogintc");
for (let i = 0; i < closelogintc.length; i++) {
    closelogintc[i].onclick = function () {
        hidesearchinput.style.display = "none";
        headimgHide.style.display = "none";
        logincover.style.display = "none";
        loginmodal.style.display = "none";
    }
}


/*登录  退出的操作！！！！ */
var tologin = document.getElementById("tologin");
tologin.onclick = function () {
    hidesearchinput.style.display = "none";
    headimgHide.style.display = "none";
    logincover.style.display = "block";
    loginmodal.style.display = "block";
}

/*开通vip进行切换新帐号的操作    实际上就是退出然后仍然显示登录vip的地方之后再显示登录的地方！！！ */
var changeqq = document.getElementById("changeqq");
changeqq.onclick = function () {
    hidesearchinput.style.display = "none";
    /*退出的操作！！！ */

    /*显示登录的弹窗 */
    cover.style.display = "none";
    modal.style.display = "none";
    logincover.style.display = "block";
    loginmodal.style.display = "block";
}
/*自定义账号注册 */
var selfaccountregisteraccount = document.getElementById("selfaccountregisteraccount");
var selfaccountregisterpassword = document.getElementById("selfaccountregisterpassword")
var selfaccountregisterbtn = document.getElementById("selfaccountregisterbtn")
selfaccountregisterbtn.onclick = function () {
    hidesearchinput.style.display = "none";
    axios({
        url: '/addUser',
        method: 'post',
        params: {
            account: selfaccountregisteraccount.value,
            password: selfaccountregisterpassword.value
        }
    })
        .then(function (data) {          
            if(data.data.data.message=="成功"){
                window.location.reload();
                $('.prompt').show().delay(1000).fadeOut();
                prompt[0].innerText = "注册成功";
            }else{
                $('.prompt').show().delay(1000).fadeOut();
                prompt[0].innerText = data.data.data.message;

            }

        })
        .catch(function (error) {
           
            console.log('失败')
        })
}

/*邮箱密码登录*/
var emailpasswordbtn = document.getElementById("emailpasswordbtn");
var emailpasswordemail = document.getElementById("emailpasswordemail");
var emailpasswordpassword = document.getElementById("emailpasswordpassword");
emailpasswordbtn.onclick = function () {
    axios({
        url: '/loginByEmail',
        method: 'post',
        params: {
            email: emailpasswordemail.value,
            password: emailpasswordpassword.value
        }
    })
    .then(function (data) {
        $('.prompt').show().delay(1000).fadeOut();
        prompt[0].innerText = "登录成功";
        window.location.reload();
        /*登录成功之后！！！！ */
        headimgHide.style.display = "none";
        logincover.style.display = "none";
        loginmodal.style.display = "none";
    })
    .catch(function (error) {
        console.log(error)
    })
}



var searchinputlis = document.getElementById("searchinputlis");
/*返回热度前八 */
// axios({
//     url: '/tenHotVideo',
//     method: 'get',
// })
//     .then(function (data) {
//         /*遍历出来之后将热度前十的弄到搜索框处 */
//         for (let i = 0; i < data.data.data.data.length; i++) {
//             searchinputlis.innerHTML +=
//                 `<li>` +
//                 `<button class="btntop">` + (i + 1) + `</button>` +
//                 `<span>` + data.data.data.data[i] + `</span>` +
//                 `</li>`
//         }
//     })
//     .catch(function (error) {
//         console.log('获取热度前八失败')
//     })




/*鼠标集中input出现下拉栏！！！ */
var searchinput = document.getElementById("searchinput");
searchinput.onclick = function (e) {
    var btntops = document.getElementsByClassName("btntop");
    for (let i = 0; i < 3; i++) {
        btntops[i].style.backgroundImage = "linear-gradient(233deg,#00d099,#00cc36)"
        btntops[i].style.color = "white"
    }

    
    hidesearchinput.style.display = "block";
    headimgHide.style.display = "none";
    /*鼠标点击内容，内容上到input里面 */
    var hidesearchinputlis = document.getElementById("searchinputlis").querySelectorAll("li")
    var hidesearchinputspans = document.getElementById("searchinputlis").querySelectorAll("span")
    for (let j = 0; j < hidesearchinputlis.length; j++) {
        hidesearchinputlis[j].onclick = function () {
            searchinput.value = hidesearchinputspans[j].innerHTML;
           
            hidesearchinput.style.display = "none";

        }
    }

    e = e || event; stopFunc(e);
}

document.onclick = function (e) {
    hidesearchinput.style.display = "none"
}



function stopFunc(e) {
    e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
}


var allonevipdivall = document.getElementsByClassName("allonevipdiv")

var allonevipdivone = document.getElementsByClassName("allonevipdiv")[0];

showhide.onclick = function () {
    allonevipdivone.style.backgroundImage = "linear-gradient(120deg,#fff7ec,#ffcb7e)"
    hidesearchinput.style.display = "none";
    if (userIdmessage.innerHTML == "") {
        wordone.style.display="none";
        wordtwo.style.display="none"
        toout.style.display = "none";
        tologin.style.display = "block"
        iflogin.innerHTML="尚未登录"
    } else {
        tologin.style.display = "none"
        toout.style.display = "block";
    }
    if (headimgHide.style.display == "none") {
        headimgHide.style.display = "block";
    } else {
        headimgHide.style.display = "none"
    }
}








/*vip */
var vipbz = document.getElementById("vipbz");
var vipts = document.getElementById("vipts");
vipbz.onmouseover = function () {
    vipts.style.display = "block"
}
vipbz.onmouseout = function () {
    vipts.style.display = "none"
}

vipbz.onclick = function () {
    /*支付vip类型处的内容变化以及背景变化 */
    allonevipdivone.style.backgroundImage = "linear-gradient(120deg,#fff7ec,#ffcb7e)"
    if(userIdmessage.innerHTML==""){
        wordone.style.display="none";
        wordtwo.style.display = "none";
        hidesearchinput.style.display = "none";
        /*点击之后开通vip的弹窗出现！！！！ */
        cover.style.display = "block";   //显示遮罩层
        modal.style.display = "block";   //显示弹出层
    }else{
        hidesearchinput.style.display = "none";
        cover.style.display = "block";   //显示遮罩层
        modal.style.display = "block";   //显示弹出层
    }

}
/*搜索框全局模糊查询 */
var gosearch = document.getElementById("gosearch");
var searchinput = document.getElementById("searchinput");
gosearch.onclick = function () {
    /*获取input内容 */
    var globalcontain = searchinput.value;
    if (globalcontain == "") {
        $('.prompt').show().delay(1000).fadeOut();
        prompt[0].innerText = "请输入搜索内容";
        hidesearchinput.style.display = "none"
    } else {
        localStorage.setItem("globalsearchcontain", globalcontain);
        window.location.href = "/globalsearch"
    }
}

for (let i = 0; i < allonevipdivall.length; i++) {
    allonevipdivall[i].onclick = function () {
        for (let i = 0; i < allonevipdivall.length; i++) {
            allonevipdivall[i].style.background = ""
        }
        allonevipdivall[i].style.backgroundImage = "linear-gradient(120deg,#fff7ec,#ffcb7e)"
        var money = document.getElementById("money");
        if (i == "0") {
            money.innerHTML = "￥10元"
        } else if (i == "1") {
            money.innerHTML = "￥25元"
        } else if (i == "2") {
            money.innerHTML = "￥50元"
        } else if (i == "3") {
            money.innerHTML = "￥80元"
        } else if (i == "4") {
            money.innerHTML = "￥100元"
        } else if (i == "5") {
            money.innerHTML = "￥135元"
        } else {
            money.innerHTML = "￥6元"
        }
    }
}



/*进行去支付！！！！ */

var vipidall = document.getElementsByClassName("vipid");
/*点击去支付 */
var payapplybtn = document.getElementById("payapplybtn");

payapplybtn.onclick = function () {

    if (userIdmessage.innerHTML == "") {
        $('.prompt').show().delay(1000).fadeOut();
        prompt[0].innerText = "尚未登录，请先登录";
    } else {
        /*登录之后先进行查询积分，然后如果签到就进行签到 */
        for (let i = 0; i < allonevipdivall.length; i++) {
            if (allonevipdivall[i].style.background !== "") {
                // alert(vipidall[i].innerHTML.replace(/^\s*|\s*$/g, ""))
                var vipId = vipidall[i].innerHTML.replace(/^\s*|\s*$/g, "")
                axios({
                    url: '/addPayOrder',
                    method: 'post',
                    params: {
                        vipId: vipId,
                        userId: userIdmessage.innerHTML,
                    }
                })
                    .then(function (data) {
                      
                        /*添加订单成功之后进行遍历订单获取订单信息 */
                        axios({
                            url: '/findOrderInnerJoinUser',
                            method: 'get',
                            params: {
                                payVipOrderId: data.data.data.object.payVipOrderId,
                            }
                        })
                            .then(function (data) {
                           
                                var payNo = data.data.data.object.payNo  //订单号码
                                var userName = data.data.data.object.userName  //订单人
                                var goodsName = data.data.data.object.goodsName  //订单vip类型名称
                                var nowPrice = data.data.data.object.nowPrice  //订单价格
                                var payVipOrderId = data.data.data.object.payVipOrderId  //订单id

                                /*进行支付 */
                                axios({
                                    url: '/payFor',
                                    method: 'get',
                                    params: {
                                        payVipOrderId: data.data.data.object.payVipOrderId,
                                    }
                                })
                                    .then(function (data) {

                                        window.location.href = 'http://42.194.158.211:8080/video/alipay/payFor?payVipOrderId' + '=' + `${payVipOrderId}`

                                        /*存储 */
                                        localStorage.setItem("payVipOrderId", `${payVipOrderId}`);


                                    })
                                    .catch(function (error) {
                                      
                                        console.log('支付订单失败')
                                    })

                            })
                            .catch(function (error) {
                               
                                console.log('遍历支付订单失败')
                            })



                    })
                    .catch(function (error) {
                        
                        console.log('添加订单失败')
                    })



            }
        }
    }
}




var toontherzh = document.getElementById("toontherzh");
var vipnickname = document.getElementById("vipnickname");
if (userIdmessage.innerHTML == "") {
    vipnickname.innerHTML = "尚未登录"
}




/*获取vip时间期限问题 */
if(userIdmessage.innerHTML!==""){
    axios({
        url: '/judgeUserVipTime',
        method: 'post',
        params: {
            userId: userIdmessage.innerHTML,
        }
    })
        .then(function (data) {
          
            
            var viptime = document.getElementById("viptime");
            // alert(data.data.data.object)
            if (data.data.data.object == "您未充值会员哦") {
                // wordone.innerHTML="";
                wordone.innerHTML = "您未充值会员哦"
                wordone.style.display = "block"
                wordtwo.innerHTML = "";
            } else if (data.data.data.object == "您的会员到期咯") {
                // wordone.innerHTML = "";
                wordone.innerHTML = "您的会员到期咯"
                wordone.style.display = "block"
                wordtwo.innerHTML = "";
            } else {
                viptime.innerHTML = data.data.data.object
                wordtwo.innerHTML = "";
                wordone.style.display = "block"
            }
    })
    .catch(function (error) {
 
        console.log('判断是否充值vip以及vip时间操作失败')
    })
}





    var vipaccount = document.getElementById("vipaccount");
if (userIdmessage.innerHTML == "") {
    vipaccount.innerHTML = "去登录"
    vipaccount.style.fontSize = "0.8em"
}
vipaccount.onclick = function () {
    if(vipaccount.innerHTML=="去登录"){
        cover.style.display="none";
        modal.style.display="none";
        logincover.style.display="block";
        loginmodal.style.display="block";
    }
}


// 去支付

var vipidall = document.getElementsByClassName("vipid");
/*点击去支付 */
var payapplybtn = document.getElementById("payapplybtn");
payapplybtn.onclick = function () {

    if (userIdmessage.innerHTML == "") {
        $('.prompt').show().delay(1000).fadeOut();
        prompt[0].innerText = "尚未登录，请先登录";
    } else {
        /*登录之后先进行查询积分，然后如果签到就进行签到 */
        for (let i = 0; i < allonevipdivall.length; i++) {
            if (allonevipdivall[i].style.background !== "") {
                // alert(vipidall[i].innerHTML.replace(/^\s*|\s*$/g, ""))
                var vipId = vipidall[i].innerHTML.replace(/^\s*|\s*$/g, "")

                axios({
                    url: '/addPayOrder',
                    method: 'post',
                    params: {
                        vipId: vipId,
                        userId: userIdmessage.innerHTML,
                    }
                })
                    .then(function (data) {
                        console.log("添加订单成功")
                        /*添加订单成功之后进行遍历订单获取订单信息 */
                        axios({
                            url: '/findOrderInnerJoinUser',
                            method: 'get',
                            params: {
                                payVipOrderId: data.data.data.object.payVipOrderId,
                            }
                        })
                            .then(function (data) {
                                var payNo = data.data.data.object.payNo  //订单号码
                                var userName = data.data.data.object.userName  //订单人
                                var goodsName = data.data.data.object.goodsName  //订单vip类型名称
                                var nowPrice = data.data.data.object.nowPrice  //订单价格
                                var payVipOrderId = data.data.data.object.payVipOrderId  //订单id

                                /*进行支付 */
                                axios({
                                    url: '/payFor',
                                    method: 'get',
                                    params: {
                                        payVipOrderId: data.data.data.object.payVipOrderId,
                                    }
                                })
                                    .then(function (data) {

                                        window.location.href = 'http://42.194.158.211:8080/video/alipay/payFor?payVipOrderId' + '=' + `${payVipOrderId}`

                                        /*存储 */
                                        localStorage.setItem("payVipOrderId", `${payVipOrderId}`);


                                    })
                                    .catch(function (error) {
                                      
                                        console.log('支付订单失败')
                                    })

                            })
                            .catch(function (error) {
                               
                                console.log('遍历支付订单失败')
                            })



                    })
                    .catch(function (error) {
                        
                        console.log('添加订单失败')
                    })



            }
        }
    }
}
